package com.example.demo.controller.AuthorControl;

import com.example.demo.entity.BackResponseEntity;
import com.example.demo.entity.requestJson.DeleteReq;
import com.example.demo.entity.requestJson.FavoritePostReq;
import com.example.demo.entity.requestJson.QueryFavPostReq;
import com.example.demo.entity.responseJson.ListResult;
import com.example.demo.entity.responseJson.PostFavoriteRes;
import com.example.demo.service.PostFavoriteService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : 洪俊新
 * @date : 2021/3/15 16:03
 * @description:
 */
@RestController
@RequestMapping("/author/favoritepost")
@Api(value = "帖子收藏接口", tags = "帖子收藏接口")
public class PostFavoriteController {
    @Autowired
    private PostFavoriteService postFavoriteService;

    @ApiOperation(value = "用户收藏帖子接口", notes = "")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @PostMapping("/insertfavoritepost")
    public BackResponseEntity<Object> insertFavoritePost(@RequestBody FavoritePostReq favoritePostReq) {
        return postFavoriteService.insertFavoritePost(favoritePostReq);
    }

    @ApiOperation(value = "查看用户收藏帖子列表接口", notes = "用于查看书架帖子和个人主页收藏帖子")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @GetMapping("/queryfavoritepost")
    public BackResponseEntity<ListResult<List<PostFavoriteRes>>> queryFavoritePost(DeleteReq deleteReq) {
        return postFavoriteService.querybookshelefPost(deleteReq);
    }

    @ApiOperation(value = "查看是否收藏帖子接口", notes = "user_id是此时登录的作者id")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @GetMapping("/isfavoritepost")
    public BackResponseEntity<Object> isFavoritePost(FavoritePostReq favoritePostReq) {
        return postFavoriteService.isfavoritePost(favoritePostReq);
    }

    @ApiOperation(value = "取消收藏帖子接口", notes = "user_id是此时登录的作者id")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @GetMapping("/unfavoritepost")
    public BackResponseEntity<Object> unFavoritePost(FavoritePostReq favoritePostReq) {
        return postFavoriteService.unSubscribePost(favoritePostReq);
    }

    @ApiOperation(value = "模糊查询收藏帖子接口", notes = "user_id是此时登录的作者id，用于书架查询")
    @ApiOperationSupport(author = "杨")
    @ApiResponses(
            @ApiResponse(code = 200, message = "处理成功")
    )

    @GetMapping("/fuzzyqueryfavpost")
    public BackResponseEntity<List<PostFavoriteRes>> fuzzyQueryFavPost(QueryFavPostReq queryFavPostReq) {
        return postFavoriteService.fuzzyQueryPost(queryFavPostReq);
    }
}
